package com.education.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.platform.entity.AuditLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 审计日志Mapper接口
 *
 * @author education-platform
 * @since 2024-09-27
 */
@Mapper
public interface AuditLogMapper extends BaseMapper<AuditLog> {

    /**
     * 分页查询审计日志（带管理员信息）
     */
    IPage<AuditLog> selectAuditLogPageWithAdmin(Page<AuditLog> page, @Param("adminId") Long adminId, 
                                                @Param("action") String action, @Param("targetType") String targetType,
                                                @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    /**
     * 根据管理员ID查询日志
     */
    List<AuditLog> selectByAdminId(@Param("adminId") Long adminId);

    /**
     * 根据操作对象查询日志
     */
    List<AuditLog> selectByTarget(@Param("targetType") String targetType, @Param("targetId") Long targetId);

    /**
     * 统计操作次数
     */
    Integer countByAction(@Param("action") String action, @Param("startTime") LocalDateTime startTime, 
                         @Param("endTime") LocalDateTime endTime);

    /**
     * 删除指定时间之前的日志
     */
    void deleteBeforeDate(@Param("beforeDate") LocalDateTime beforeDate);
}

